#!/usr/bin/python
# -*- coding: utf-8 -*-
# Created by binhou.li on 02/03/2018
# @Copyright

import config
import logging


def exec_dql_sql(data_query_sql):
    '''
    Execute data query sql.
    :param data_query_sql: sql string
    :return: result
    '''
    log_msg = "execute sql: %s" % data_query_sql
    logging.debug(log_msg)
    con = config.db_connection()
    cursor = con.cursor()
    cursor.execute(data_query_sql)
    result = cursor.fetchall()
    cursor.close()
    con.close()
    return result

def exec_dml_sql(data_modify_sql):
    '''
    Execute data modify sql.
    :param data_modify_sql: sql string
    :return:
    '''
    log_msg = "execute sql: %s" % data_modify_sql
    logging.debug(log_msg)
    con = config.db_connection()
    cursor = con.cursor()
    cursor.execute(data_modify_sql)
    cursor.close()
    con.commit()
    con.close()
